package com.gragra.innerProducts;
import com.google.common.collect.Multiset;
/**
 * Simple class that allows viewing Multisets as vectors and calculate their inner product.
 * @author Christoph Teichmann
 * @version 0.1
 */
public class InnerForMultiset
{
	/**
	 * returns the inner product of the two multisets seen as vectors over their entries
	 * @param m
	 * @param n
	 * @return
	 */
	public static double make(final Multiset<Integer> m,
			final Multiset<Integer> n)
	{
		double ret = 0.0;
		for (final Multiset.Entry<Integer> ent : m.entrySet())
		{
			final Integer k = n.count(ent.getElement());
			ret += k * ent.getCount();
		}
		return ret;
	}
}